<template>
  <div class="xtx_navs" @mousemove="move=true">
    <ul v-if="cateList.length && showNav">
      <li>
        <router-link to="/">首页</router-link>
      </li>
      <li
        @click="reset()"
        v-for="item in cateList"
        :key="item.id"
        :class="{move}"
      >
        <router-link :to="`/category/${item.id}`">{{ item.name }}</router-link>
        <!-- 二级分类 -->
        <div class="xtx-second-nav">
          <ul>
            <li v-for="item2 in item.children" :key="item2.id">
              <router-link :to="`/category/sub/${item2.id}`">
                <img width="60" height="60" :src="item2.picture" alt />
                <p>{{ item2.name }}</p>
              </router-link>
            </li>
          </ul>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'app-header-nav',
  props: ['cateList'],
  data () {
    return {
      move: false,
      showNav: true,
      list: []
    }
  },
  methods: {
    reset () {
      this.showNav = false
      this.move = false
      this.$nextTick(() => {
        this.showNav = true
      })
    }
  }
}
</script>

<style scoped lang='less'>
.xtx_navs {
  padding-left: 50px;
  flex: 1;
  > ul {
    > li {
      font-size: 16px;
      margin-right: 44px;
      float: left;
      border-bottom: 2px solid transparent;
      line-height: 30px;
      margin-top: 2px;
      // 移动过加上鼠标进入效果
      &.move {
        &:hover {
          border-bottom-color: @xtxColor;
          > a {
            color: @xtxColor;
          }
          .xtx-second-nav {
            height: 132px;
            opacity: 1;
          }
        }
      }
      .xtx-second-nav {
        position: absolute;
        left: 0;
        top: 100px;
        background: #fff;
        width: 100%;
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
        transition: all 0.3s 0.2s;
        padding: 0 50px;
        z-index: 999;
        height: 0;
        opacity: 0;
        overflow: hidden;
        > ul {
          display: flex;
          flex-wrap: wrap;
          > li {
            width: 10%;
            text-align: center;
            padding-top: 20px;
            &:hover {
              p {
                color: @xtxColor;
              }
            }
            p {
              padding-top: 10px;
            }
          }
        }
      }
    }
  }
}
</style>
